package com.ruoyi.buy.service.impl;

import com.ruoyi.buy.domain.entity.PO.BuyUserBrand;
import com.ruoyi.buy.domain.entity.buy0010.Buy0010TableData;
import com.ruoyi.buy.mapper.PO.BuyUserBrandMapper;
import com.ruoyi.buy.mapper.PO.buy0010.Buy0010Mapper;
import com.ruoyi.buy.service.IBuy0010Service;
import com.ruoyi.buy.service.ICommonService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 参数配置 服务层实现
 * 
 * @author ruoyi
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class Buy0010ServiceImpl implements IBuy0010Service
{

    @Resource
    private Buy0010Mapper buy0010Mapper;

    @Resource
    private BuyUserBrandMapper buyUserBrandMapper;

    @Autowired
    private ICommonService commonService;

    @Override
    public List<Buy0010TableData> getList(Buy0010TableData param) {
        return buy0010Mapper.getList(param);
    }

    @Override
    public List<BuyUserBrand> getBrandListByUser(BuyUserBrand param) {
        param.setStatus("1");
        return this.buyUserBrandMapper.selectBuyUserBrandList(param);
    }

    @Override
    public void save(List<BuyUserBrand> list) {

        for (BuyUserBrand item:list
             ) {

            if (item.getId() == null){
                item.setCreateTime(DateUtils.getNowDate());
                item.setCreateBy(commonService.getUsername());
                this.buyUserBrandMapper.insertBuyUserBrand(item);
            }else {
                item.setUpdateTime(DateUtils.getNowDate());
                item.setUpdateBy(commonService.getUsername());
                this.buyUserBrandMapper.updateBuyUserBrand(item);
            }
        }

    }

    @Override
    public void deleteItem(BuyUserBrand item) {
        this.buyUserBrandMapper.deleteBuyUserBrandById(item.getId());
    }
}
